package com.wyb.fastdfs.utils;

public class FastDfsUtil {

//	private static Logger logger = LoggerFactory.getLogger(FastDfsUtil.class);
//
//	private static final String CONF_FILENAME = "fdfs_client.conf";
//	static {
//		String filePath = (FastDfsUtil.class.getClass().getResource("/").getPath() + CONF_FILENAME).replaceAll("//",
//				"\\");
//		try {
//			ClientGlobal.init(filePath);
//		} catch (IOException e) {
//			e.printStackTrace();
//		} catch (MyException e) {
//			e.printStackTrace();
//		}
//	}

	/**
	 * 功能描述：文件上传
	 * 
	 * @author dayibalang
	 * @date 2020/7/22
	 * @param file
	 * @return java.lang.String
	 */
//	public static String uploadFile(File file) throws IOException, MyException {
//		FileInputStream fis = null;
//		NameValuePair[] meta_list = null;
//		TrackerClient trackerClient = new TrackerClient(ClientGlobal.g_tracker_group);
//		TrackerServer trackerServer = trackerClient.getTrackerServer();
//		StorageServer storageServer = trackerClient.getStoreStorage(trackerServer);
//		StorageClient1 storageClient = new StorageClient1(trackerServer, storageServer);
//		fis = new FileInputStream(file);
//		byte[] file_buff = null;
//		if (fis != null) {
//			int len = fis.available();
//			file_buff = new byte[len];
//			fis.read(file_buff);
//		}
//		String fileId = storageClient.upload_file1(file_buff, getFileExt(file.getName()), meta_list);
//		return fileId;
//	}
//
//	/**
//	 * 功能描述：文件下载
//	 * 
//	 * @author dayibalang
//	 * @date 2020/7/22
//	 * @param fileId
//	 * @return java.io.InputStream
//	 */
//	public static InputStream downloadFile(String fileId) throws IOException, MyException {
//		TrackerClient trackerClient = new TrackerClient(ClientGlobal.g_tracker_group);
//		TrackerServer trackerServer = trackerClient.getTrackerServer();
//		StorageServer storageServer = trackerClient.getStoreStorage(trackerServer);
//		StorageClient1 storageClient = new StorageClient1(trackerServer, storageServer);
//		byte[] bytes = storageClient.download_file1(fileId);
//		InputStream inputStream = new ByteArrayInputStream(bytes);
//		inputStream.close();
//		return inputStream;
//	}
//
//	/**
//	 * 功能描述：获取文件名后缀(不包含点)
//	 * 
//	 * @author dayibalang
//	 * @date 2020/7/22
//	 * @param fileName
//	 * @return java.lang.String
//	 */
//	private static String getFileExt(String fileName) {
//		if (fileName == null || !fileName.contains(".")) {
//			return "";
//		} else {
//			return fileName.substring(fileName.lastIndexOf(".") + 1); // 不带最后的点
//		}
//	}
//
//	/**
//	 * 功能描述： 删除文件
//	 * 
//	 * @author dayibalang
//	 * @date 2020/7/22
//	 * @param fileId
//	 * @return int
//	 */
//	public static int deleteFile(String fileId) throws IOException, MyException {
//		TrackerClient trackerClient = new TrackerClient(ClientGlobal.g_tracker_group);
//		TrackerServer trackerServer = trackerClient.getTrackerServer();
//		StorageServer storageServer = trackerClient.getStoreStorage(trackerServer);
//		StorageClient1 storageClient = new StorageClient1(trackerServer, storageServer);
//		int result = storageClient.delete_file1(fileId);
//		return result;
//	}

}
